﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using DMS.Business.Modules.Statistics;
using System.Text;
using InfoSoftGlobal;
using DMS.Business.Utility;

namespace DMS.Web.Modules.Statistics
{
    public partial class StatByDeptTotalControl : System.Web.UI.UserControl
    {
        private int _chartWidth=400;
        public int ChartWidth
        {
            get
            {
                return _chartWidth;
            }
            set
            {
                _chartWidth = value;
            }
        }

        private int _chartHeigth = 400;
        public int ChartHeight
        {
            get
            {
                return _chartHeigth;
            }
            set
            {
                _chartHeigth = value;
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Stat();
            }
        }

        private void Stat()
        {
            string condition = "";//string.Format(" and InitialTime >= '{0}'", new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1));

            DataSet ds = new StatService().StatByDept(condition);

            DrawChart(ds);
        }

        /// <summary>
        ///  画图
        /// </summary>
        private void DrawChart(DataSet ds)
        {
            StringBuilder xmlData = new StringBuilder();
            xmlData.Append(
                string.Format(
                    "<chart caption='各分局参保户数占比统计(%)' showAboutMenuItem='0' palette='4' decimals='2' enableSmartLabels='1' enableRotation='0' bgAngle='360' showBorder='0' startingAngle='70' >"));

            if (ds != null && ds.Tables[0].Rows.Count > 0)
            {
                foreach (DataRow row in ds.Tables[0].Rows)
                {
                    xmlData.Append(string.Format("<set label='{0}' value='{1}' />", row["name"],
                                                 row["rate"]));
                }
            }
            xmlData.Append("</chart>");
            
            litChart.Text = FusionCharts.RenderChart("../../FusionCharts/Doughnut3D.swf", "", xmlData.ToString(),
                                                     "myChart3", "100%", ChartHeight.ToString(), false, true);
        }
    }
}